<link rel="stylesheet" type="text/css" href="css/accourt.css"/>
<link rel="stylesheet" href="css/trecord.css" media="all" />
<link rel="stylesheet" href="css/page.css" media="all" />
<script type="text/javascript" src="js/Calendar.js"></script>
<script type="text/javascript" src="js/global/Date_func.js"></script>
<div class="r_content" id="spe_w">
	<?include("account_bar.tpl")?>
	<div class="accoinfo accos">
		<form id="searchBox">
            <input type="hidden" name="act" id="act"/>
			<input type="hidden" name="timeT" id="timeT" value=""/>
			<input type="hidden" name="dtype" id="dtype" value="<?=$_REQUEST['dtype']?>"/>
			<input type="hidden" name="daction" id="daction" value="<?=$_REQUEST['daction']?>"/>
			<input type="hidden" name="about" id="about" value="<?=$about?>"/>
			<input type="hidden" name="account" id="account" value="<?=$_REQUEST['account']?>"/>
			<ul class="search">
				<li class="time">
					<span class="leaderTxt">起止日期：</span>
					<input type="text" name="beginDate" id="begintime" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$_REQUEST['beginDate']?>"/>
					<label>至</label>
					<input type="text" name="endDate"  id="endtime" onmouseup="SelectDate(this,'yyyy-MM-dd',0,0)" value="<?=$_REQUEST['endDate']?>"/>
					<a title="today" class="<?=$_REQUEST['timeT']=="today"?"current":""?>">今天</a>
					<a title="yesterday" class="<?=$_REQUEST['timeT']=="yesterday"?"current":""?>">昨天</a>
					<a title="week" class="<?=$_REQUEST['timeT']=="week"?"current":""?>">本周</a>
					<a title="lastweek" class="<?=$_REQUEST['timeT']=="lastweek"?"current":""?>">上周</a>
					<a title="month" class="<?=$_REQUEST['timeT']=="month"?"current":""?>">本月</a>
					<a title="lastmonth" class="<?=$_REQUEST['timeT']=="lastmonth"?"current":""?>">上月</a>
					
				</li>
                <li class="skey">
                    <span class="leaderTxt">订单号：</span >
                    <input class="setInp w437" name='orderid'  value="<?=$_GET['orderid']?>"/>
       
                </li>
				<li class="skey">
					<span class="leaderTxt">交易类型：</span>
					<a class="<?=!isset($_REQUEST['dtype'])||($_REQUEST['dtype']==="")?"current":""?>" key="dtype" kvalue="">全部</a>
					<a class="<?=$_REQUEST['dtype']==='0'?"current":""?>" key="dtype" kvalue="0">下单</a>
					<a class="<?=$_REQUEST['dtype']==='1'?"current":""?>" key="dtype" kvalue="1">撤改</a>
                    <?if(!$access['yd']):?>
					<a class="<?=$_REQUEST['dtype']==='3'?"current":""?>" key="dtype" kvalue="3">充值</a>
					<a class="<?=$_REQUEST['dtype']==='4'?"current":""?>" key="dtype" kvalue="4">授信/预存</a>
                    <a class="<?=$_REQUEST['dtype']==='6'?"current":""?>" key="dtype" kvalue="6">提现冻结</a>
                    <?endif;?>
					<a class="<?=$_REQUEST['dtype']==='5'?"current":""?>" key="dtype" kvalue="5">分润</a>                   
                    <a class="<?=$_REQUEST['dtype']==='15'?"current":""?>" key="dtype" kvalue="15">联盟分润</a>
					
				</li>
                <?if(!$access['yd']):?>
				<?if($_SESSION['dtype']==0){?>
				<li class="skey">
					<span class="leaderTxt">运营支付：</span>
					<a class="<?=!isset($_REQUEST['dtype'])||($_REQUEST['dtype']==="")?"current":""?>" key="dtype" kvalue="">全部</a>
					<a class="<?=$_REQUEST['dtype']==='7'?"current":""?>" key="dtype" kvalue="7">电子凭证费</a>
					<a class="<?=$_REQUEST['dtype']==='8'?"current":""?>" key="dtype" kvalue="8">短信费</a>
					<a class="<?=$_REQUEST['dtype']==='9'?"current":""?>" key="dtype" kvalue="9">交易手续费</a>
				</li>
				<?}?>
                <?endif;?>
				<li class="skey">
					<span class="leaderTxt">收支情况：</span>
					<a class="<?=!isset($_REQUEST['daction'])||($_REQUEST['daction']==="")?"current":""?>" key="daction" kvalue="">全部</a>
					<a class="<?=$_REQUEST['daction']==='0'?"current":""?>" key="daction" kvalue="0">收入</a>
					<a class="<?=$_REQUEST['daction']=='1'?"current":""?>" key="daction" kvalue="1">支出</a>
					
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				</li>
				<li class="skey">
					<span class="leaderTxt">交易账号：</span>
					<!--
					<a class="<?=!isset($_REQUEST['account'])||($_REQUEST['account']==="")?"current":""?>" key="account" kvalue="">全部</a>-->
					<a class="<?=$_REQUEST['account']=='alipay'?"current":""?>" key="account" kvalue="alipay">在线支付</a>
                    <?if(!$access['yd']):?>
					<a class="<?=$_REQUEST['account']=='pft'?"current":""?>" key="account" kvalue="pft">平台账户</a>
                     <?endif;?>
					<a class="<?=$_REQUEST['account']=='credit'?"current":""?>" key="account" kvalue="credit">我的信用账户</a>
                    <a class="<?=$_REQUEST['account']=='credit_mid'?"current":""?>" key="account" kvalue="credit_mid">分销商信用账户</a>
					<a class="<?=$_REQUEST['account']=='creditSet'?"current":""?>" key="account" kvalue="creditSet">授信设置</a>
                    <?if(!$access['yd']):?>
					<a class="<?=$_REQUEST['account']=='ipsPay'?"current":""?>" key="account" kvalue="ipsPay">网银</a>
                    <?endif;?>
                    <a class="<?=$_REQUEST['account']=='tenpay'?"current":""?>" key="account" kvalue="tenpay">在线收入</a>
				</li>
                <li>
                    <input type="submit" id="query" value="查询"/>
                    <input type="button" class="export exportbtn" value="导出" id="excel"/>
                
                </li>
               
			</ul>
		</form>
	</div>
	<div class="acclist">
		<table class="acctab">
			<thead>
				<tr>
					<th class="tL">交易时间</th>
					<th>订单号</th>
					<th>交易内容</th>
					<th><?
                        switch ($_GET['account']) {
                        	case 'credit':
                        		echo '供应商名称';
                        		break;
                            case 'credit_mid':
                                echo '分销商名称';
                                break;
                        	default:
                        		echo '交易方式';
                        		break;
                        }
                        ?></th>
					<th class="tR">收入</th>
                    <th class="tR">支出</th>
					<th class="tR">银行账户</th>
                    <?if(!$access['yd']):?>
					<th class="tR">账户余额</th>
                    <?endif;?>
					<th class="tR">授信余额</th>
					<th class="tR">备注</th>
				</tr>
			 </thead>
			  <tbody>
				<?
                $ptype_arr = array(0,1,4,5,6);
                foreach($r as $row){
                    $i++;
                    ?>
				<tr class="<?=($i%2==1)?"odd":"even"?>">
					<td class="tL" title="<?=$row['id']?>"><?=$row['rectime']?></td>
					<td><a target="_blank" data-ac="<?=$row['dtype']?>" href="orderView.html?from=
					<?
					if($row['orderid']){
						if($row['dtype']==8){//短信费一定是卖
							$sob = 'sale'; //sale or buy
                        }else{
							/*
							 * 查询订单 判断是否取消 没取消的订单就看金额是正是负来确定买还是卖
							 * 把订单存起来 以免重复查询
							 * 如果取消了 那么判断这一行的时候在取消前还是取消后 取消前的 金额增加就是卖 取消后的 则反之
							 */
							if((string)$orders[$row['orderid']]->Rec->UUctime=='0000-00-00 00:00:00')
					//            echo
                                $sob = $row['daction']==1 ? 'buy' : 'sale';
							else{
								if((string)$orders[$row['orderid']]->Rec->UUctime<=$row['rectime'])
                                    $sob = $row['daction']==0 ? 'buy' : 'sale';
								else
                                    $sob =$row['daction']==1 ? 'buy' : 'sale';
							}
						}
					}
                        echo $sob;
					?>&ordernum=<?=$row['orderid']?>"><?=$row['orderid']?></a></td>

                    <?if($row['daction']==2):?>
                    <td>退款手续费</td>
                    <?else:?>
                    <td><?=$dtypeT[$row['dtype']]?$dtypeT[$row['dtype']]:$row['dtypeT']?></td>
                    <?endif;?>
					
					<td><?
                        switch ($_GET['account']) {
                        	case 'credit':
                        		echo $dnames[$row['aid']];
                        		break;
                            case 'credit_mid':
                                echo $dnames[$row['fid']];
                                break;
                        	default:
                                if($row['ptype'] == -1)
                                    switch ($row['sourceT']) {
                                        case '0':
                                            echo '支付宝';
                                            break;
                                        case '1':
                                            echo '微信';
                                            break;
                                        case '2':
                                            echo '银联';
                                            break;
                                        case '3':
                                            echo '环迅';
                                            break;
                                        default:
                                            echo '支付宝';
                                    }else echo $ptypeT[$row['ptype']];
                        		break;
                        }
                        ?></td>
                    <?//if($row['daction']==2):?>
                    <td class="income pay tR"><?=$row['income']?></td>
                    <?//else:?>
                    <td class="income pay tR"><?=$row['pay']?></td>
                    <?//endif;?>
					
					<td class="lmoney tR"><?=$row['alipay']?></td>
                    <?if(!$access['yd']){?>
                    <td class="lmoney tR"><?=in_array($row['ptype'],$ptype_arr)?$row['lmoney']/100:""?></td>
                     <?}?>
					<td class="lmoney tR"><?=($row['ptype']==2||$row['ptype']==3)?($row['lmoney']/100):""?></td>
                    <td class="lmoney tR setTd"><?=$row['memo']?></td>
				</tr>
				<?
                    /*
                if($row['onsale']==1&&!$onsale[$row['orderid']]){
                    $onsale[$row['orderid']]=1;
                    $i++;
                    $sql = "select id,eMoney from pft_onsale_record where ordernum='{$row['orderid']}' limit 1";
                    $GLOBALS['le']->query($sql);
                    $eMoney = $GLOBALS['le']->fetch_assoc();
                    if($eMoney['id']){
                  ?>
                    <tr class="<?=($i%2==1)?"odd":"even"?>">
                        <td class="tL" title="<?=$row['id']?>"><?=$row['rectime']?></td>
                        <td><a target="_blank" data-ac="<?=$row['dtype']?>" href="orderView.html?from=<?=$sob?>&ordernum=<?=$row['orderid']?>"><?=$row['orderid']?></a></td>
                        <td ><?=$dtypeT[0]?></td>
                        <td >优惠券</td>
                        <td class="lmoney tR"></td>
                        <td class="lmoney pay tR">-<?=$eMoney['eMoney']/100?></td>
                        <td class="lmoney tR"></td>
                        <td class="lmoney tR"></td>
                        <td class="lmoney tR"></td>
                        <td class="lmoney tR">优惠券编号:<?=$eMoney['id']?></td>
                    </tr>
                   <?}}*/}
                ?>
				<?if(count($r)==0){?>
					<tr><td colspan="7" style="text-align:left; padding-left:60px;">无资金流向记录</td></tr>
				<?}?>
			</tbody>
		</table>
		<?if(count($r)!=0){page($count,$currentPage,$pageSize);}?>
	</div>
</div>
<script>
$(".search li.time a").click(function(){
    var title=$(this).attr("title");
    Date_func.selectDate(title,document.getElementById("begintime"),document.getElementById("endtime"));
    $("#timeT").val(title)
    $("#searchBox").submit();
})
$(".search li.skey a").click(function(){
    var key=$(this).attr("key");
    $("#"+key).val($(this).attr("kvalue"));
    $("#searchBox").submit();
})
$("#excel").click(function(){
    $("#act").val("Export");
    $("#searchBox").submit();
    $("#act").val("");
});
    <?if($_GET['account']=='credit' || $_GET['account']=='credit_mid' || $_GET['account']=='creditSet'){?>//取授信的时候 把银行余额和账户余额隐藏了
    $(".acctab thead tr th").each(function(i){
        if(i==6
        <?if(!$access['yd']):?>
            || i==7
        <?endif;?>){
            $(this).hide();
        }
    })
    $(".acctab tbody tr").each(function(){
        $(this).children('td').each(function(i){
            if(i==6
            <?if(!$access['yd']):?>
                || i==7
            <?endif;?>){
                $(this).hide();
            }
        })
    })
    <?}elseif(!$access['yd']){?>
        $(".acctab thead tr th").each(function(i){
            if(i==8){
                $(this).hide();
            }
        })
        $(".acctab tbody tr").each(function(){
            $(this).children('td').each(function(i){
                if(i==8){
                    $(this).hide();
                }
            })
        })
    <?}?>
</script>